package demo5.example;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: java-generic
 * @description:
 * @author: bjc
 * @create: 2021-08-15 15:51
 */
public class Main {

    public static void main(String[] args) {
        List<Animal> animals = new ArrayList<>();
        List<Cat> cats = new ArrayList<>();
        List<MiniCat> miniCats = new ArrayList<>();

        //报错
//        showAnimal(animals);

        showAnimal(cats);
        showAnimal(miniCats);
    }

    /**
     * 泛型上限通配符，传递的集合类型，只能是Cat或Cat的子类类型
     * TODO  不能在方法中填充属性
     * @param list
     */
    public static void showAnimal(List<? extends Cat> list){
        for (int i = 0; i < list.size(); i++) {
            Cat cat = list.get(i);
            System.out.println(cat);
        }
    }
}
